from time import sleep
from selenium.webdriver.common.keys import Keys
from selenium import webdriver
driver=webdriver.Firefox()
driver.get("http://mail.163.com/")

driver.switch_to.frame(driver.find_element_by_tag_name("iframe"))
sleep(1)
driver.find_element_by_name("email").clear()
driver.find_element_by_name("email").send_keys("Inception0617")
driver.find_element_by_name("password").clear()
driver.find_element_by_name("password").send_keys("13671281279")
sleep(1)
driver.find_element_by_id("dologin").click()
driver.switch_to.default_content()

# xiexin_css='#_mail_component_24_24 > span:nth-child(2)'
# driver.find_element_by_css_selector(xiexin_css).click()
# sleep(2)
# # driver.find_element_by_id('_mail_component_24_24').click()
# xiexin_css='#_mail_component_24_24 > span:nth-child(2)'
# driver.find_element_by_css_selector(xiexin_css).click()
# driver.find_element_by_id('_mail_component_24_24').click()
sleep(12)
xiexin_xp='//*[@id="_mail_component_24_24"]'
driver.find_element_by_xpath(xiexin_xp).click()
sleep(2)
#填写收件人
driver.find_element_by_css_selector('.nui-editableAddr-ipt').send_keys('ma_linpop@163.com')
#填写标题
driver.find_element_by_xpath('/html/body/div[2]/div[1]/div[2]/div[1]/section/header/div[2]/div[1]/div/div/input').send_keys('北京石油化工学院_计171_王子昂  自动化懒人发送邮件')
#填写内容
driver.switch_to.frame(driver.find_element_by_class_name("APP-editor-iframe"))
driver.find_element_by_css_selector('body').send_keys('吃葡萄我就不吐葡萄皮！！！')
driver.switch_to.default_content()
# 定位"上传附件"
sleep(3)
driver.find_element_by_xpath("//input[@type='file' and @class='O0']").send_keys("C:\\这只是个自动化测试.txt")
sleep(3)
#点击发送
#_mail_button_8_197 > span:nth-child(2)   #_mail_button_8_198 > span:nth-child(2)
  #_mail_button_8_198 > span:nth-child(2)   #_mail_button_8_194 > span:nth-child(2)         #_mail_button_8_191 > span.nui-btn-text                       #_mail_button_8_190 > span:nth-child(2)      #_mail_button_8_196 > span:nth-child(2)
driver.find_element_by_css_selector('#_mail_button_8_198 > span:nth-child(2)').click()
sleep(5)